package com.atguigu.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;

public class Hbase_Connect_Single {
    public static Connection connection=null;

    static {
        //创建配置对象
        Configuration configuration = new Configuration();

        //设置连接属性
        configuration.set("hbase.zookeeper.quorum", "hadoop102,hadoop103,hadoop104");

        try {
            //获取连接
            if (connection==null){
                connection = ConnectionFactory.createConnection(configuration);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void closeConnect() throws IOException {
        if (connection!=null){
            connection.close();
        }
    }



    public static void main(String[] args) throws IOException {
        //调用连接
        Connection connection = Hbase_Connect_Single.connection;

        System.out.println(connection);

        //关闭连接
        Hbase_Connect_Single.closeConnect();
    }
}
